<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

function getConnect() {
    // 连接MySQL数据库的DSN(Data Sourse Name)
    $dsn = 'mysql:host=localhost;dbname=plantsdata';
    // MySQL数据库的用户名
    $username = 'root';
    // MySQL数据库的密码
    $password = '';
    try {
        $pdo = new PDO($dsn, $username, $password);
    } catch (PDOException $e) {
        die('数据库连接失败：' . $e->getMessage());
    }

    // 解决中文乱码问题
    $pdo->exec('SET NAMES utf8');

    return $pdo;
}
